package com.cskaoyan.catmall.controller.background;


import com.cskaoyan.catmall.annotation.OperationLog;
import com.cskaoyan.catmall.model.bo.BrandDeleteBo;
import com.cskaoyan.catmall.model.bo.BrandListBo;
import com.cskaoyan.catmall.model.bo.BrandCreateBo;
import com.cskaoyan.catmall.model.bo.BrandUpdateBo;
import com.cskaoyan.catmall.model.vo.BaseRespVo;
import com.cskaoyan.catmall.model.vo.BrandCreateVo;
import com.cskaoyan.catmall.model.vo.BrandListVo;
import com.cskaoyan.catmall.service.BrandService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 创建日期: 2022-01-07-13-31
 * author : WQW
 * description: 品牌相关接口
 */

@RestController
@RequestMapping("admin/brand")
public class BrandController {


    @Autowired
    BrandService brandService;


    /**
     * @param
     * @param brandListBo
     * @return com.cskaoyan.catmall.model.vo.BaseRespVo
     * @description 查询品牌信息
     * @author WQW
     * @date 2022/1/7 20:03
     */
    @OperationLog("查询品牌商")
    @RequiresPermissions("admin:brand:list")
    @GetMapping("list")
    public BaseRespVo list(@Validated BrandListBo brandListBo, BindingResult bindingResult) {
        BrandListVo brandList = brandService.getBrandList(brandListBo);
        return BaseRespVo.ok(brandList);
    }


    /**
     * @param
     * @param brandCreateBo
     * @return com.cskaoyan.catmall.model.vo.BaseRespVo
     * @description 新增品牌信息
     * @author WQW
     * @date 2022/1/7 20:02
     */
    @OperationLog("新增品牌商")
    @RequiresPermissions("admin:brand:create")
    @PostMapping("create")
    public BaseRespVo create(@RequestBody @Validated BrandCreateBo brandCreateBo, BindingResult bindingResult) {
        BrandCreateVo brand = brandService.createBrand(brandCreateBo);
        if (brand.getId() != null) {
            return BaseRespVo.ok(brand);
        }
        return BaseRespVo.fail("创建品牌商信息失败，请稍后重试");
    }


    /**
     * @param
     * @param brandDeleteBo
     * @return com.cskaoyan.catmall.model.vo.BaseRespVo
     * @description 删除指定品牌商
     * @author WQW
     * @date 2022/1/7 20:41
     */

    @OperationLog("删除品牌商")
    @RequiresPermissions("admin:brand:delete")
    @PostMapping("delete")
    public BaseRespVo delete(@RequestBody @Validated BrandDeleteBo brandDeleteBo) {
        int result = brandService.deleteBrand(brandDeleteBo);
        if (result == 200) {
            return BaseRespVo.ok();
        }
        return BaseRespVo.fail("删除品牌商信息失败，请稍后重试");
    }


    /**
     * @param
     * @param updateBo
     * @return com.cskaoyan.catmall.model.vo.BaseRespVo
     * @description 修改品牌商信息
     * @author WQW
     * @date 2022/1/8 17:02
     */

    @OperationLog("修改品牌商")
    @RequiresPermissions("admin:brand:update")
    @PostMapping("update")
    public BaseRespVo update(@RequestBody @Validated BrandUpdateBo updateBo,BindingResult bindingResult) {
        int result = brandService.updateBrand(updateBo);
        if (result == 200) {
            return BaseRespVo.ok();
        }
        return BaseRespVo.fail("修改品牌商信息失败，请稍后重试");
    }
}
